package com.example.malllocationserver.utils;


import java.util.*;

public class CreateGraph {//工具类
    private static Queue<String>  queue = new LinkedList<>();//静态队列，用于从returnShortestDistance（）里获得路径队列
    private static List<Float[]>  Output=new ArrayList<>();
    private static float[] Inner;//内部所有点的像素坐标

    public static void startShortestDistance(int floorNumber, int source, int target) {
        Output.clear();
        queue.clear();
        //创建顶点名称，获取方便后面打印路径
        //后期将floorNumber使用上
        String[] vexs;
        if (floorNumber == 3)
            vexs = new String[]{"A0","B1","C2","D3","E4","F5","G6","H7","I8","J9","K10","L11","M12","N13","O14"};//三楼
        else if (floorNumber == 4)
            vexs = new String[]{"A0", "B1", "C2", "D3", "E4", "F5", "s6", "G7", "H8", "I9", "J10", "K11", "L12", "M13"};//四楼
        else vexs = new String[]{"A0","B1","C2","D3","E4","F5","G6","H7","I8","J9","K10","L11","M12"};//五楼


        int len = vexs.length;
        int[][] graph = creat_Graph(floorNumber, len);
        //path记录路径
        int[] path = new int[len];
        //vex代表源点
        int distance = Dijkstra.dijkstra(graph, path, len, source, target);
        queue = Dijkstra.print_road(path, vexs, len, source, target);//先有最短距离，后有图


        while (!queue.isEmpty()) {
            int a = 0;
            for (String element : vexs) {
                if (element.equals(queue.peek())) {
                    Float[] myArray =new Float[2];
                    myArray[0]=Inner[2*a];
                    myArray[1]=Inner[2*a+1];
                    Output.add(myArray);
                    queue.poll();
                    break;
                }
                a++;
            }
        }
     /*   Output = new float[tem.size()];
        for (int i = 0; i < tem.size(); i++) {
            Output[i] = tem.get(i);
        }*/
    }


    public static List<Float[]> getList() {

        return Output;
    }

    private static int[][] creat_Graph(int floorNumeber, int len) {
        //创建邻接矩阵
        int m = 999999;//用厘米？
        int[][] graph = new int[len][len];
        //初始化邻接矩阵
        for (int i = 0; i < graph.length; i++)
            for (int j = 0; j < graph[0].length; j++) {
                if (i == j)
                    graph[i][j] = 0;
                else
                    graph[i][j] = m;
            }
        if (floorNumeber == 4) {
            //根据图输入数据
            //401/415的子路径
            graph[0][1] = 1194;
            graph[0][2] = 1659;//厘米
            //楼梯1的子路径
            graph[1][2] = 510;
            //414/402的子路径
            graph[2][3] = 1102;
            //413/403的子路径
            graph[3][4] = 1161;
            //楼梯2的子路径
            graph[4][5] = 444;
            //转角的子路径
            graph[5][6] = 297;
            //s1的子路径
            graph[6][7] = 473;
            graph[6][8] = 802;
            //411的子路径
            graph[7][8] = 1189;
            //404的子路径
            graph[8][9] = 1003;
            //410的子路径
            graph[9][10] = 374;
            graph[9][11] = 1005;
            //楼梯3子路径暂无
            //405/409子路径
            graph[11][12] = 1225;
            //408/406子路径
            graph[12][13] = 1380;
            //创建内部像素点,四楼14个点
            Inner = new float[]{86F, 67F, 86F, 128F, 86F, 140F, 86F, 206F, 86F, 273F, 86F, 300F, 86F, 320F, 95F, 337F, 137F, 354F, 137F, 513F, 157F,513F,137F, 538F,  137F, 611F, 137F, 672F};
        }

        if (floorNumeber == 3) {
            //根据图输入数据
            graph[0][1] = 1194;
            graph[0][2] = 1659;//厘米
            graph[1][2] = 510;
            graph[2][3] = 1102;
            graph[3][4] = 1161;
            graph[4][5] = 244;
            graph[4][6] = 444;
            graph[6][7] = 297;
            graph[7][8] = 473;
            graph[7][9] = 802;
            graph[8][9] = 1189;
            graph[9][10] = 1003;
            graph[10][11] = 374;
            graph[10][12] = 1005;
            graph[12][13] = 1225;
            graph[13][14] = 1380;
            Inner = new float[]{82F, 60F, 110F, 120F, 82F, 164F, 82F, 220F, 82F, 275F, 115F, 275F, 82F, 300F, 115F, 300F,   115F, 360F, 135F,360F, 135F, 460F, 165F, 460F,135F,500F,135F,575F,145F,625F};

        }
        if (floorNumeber == 5) {
            //根据图输入数据
            graph[0][1] = 1194;
            graph[0][2] = 1659;//厘米
            graph[1][2] = 510;
            graph[2][3] = 1102;
            graph[3][4] = 1161;
            graph[4][5] = 444;
            graph[5][6] = 297;
            graph[6][7] = 802;
            graph[7][8] = 1003;
            graph[8][9] = 274;
            graph[8][10] = 805;
            graph[10][11] = 906;
            graph[11][12] = 1225;

            Inner = new float[]{82F, 52F, 110F, 105F, 82F, 164F, 82F, 225F, 82F, 280F, 82F, 310F, 100F, 345F, 130F, 385F, 135F, 455F, 160F, 455F, 135F, 500F, 135F, 575F, 135F, 625F};

        }
        return graph;
    }
}